package com.qlk.vorder.manager.impl;

import java.util.List;

import com.qlk.common.manager.BaseManager;
import com.qlk.common.utils.page.PageUtil;
import com.qlk.vorder.domain.ReserveSession;
import com.qlk.vorder.domain.query.ReserveSessionQuery;
import com.qlk.vorder.dao.ReserveSessionDao;
import com.qlk.vorder.manager.ReserveSessionManager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * ReserveSessionManager接口的实现类
 * 
 * @author zhaoyanan
 * @version 2016-7-28 14:14:00
 * 
 */
@Component
public class ReserveSessionManagerImpl extends BaseManager implements ReserveSessionManager {

	@Autowired
	private ReserveSessionDao reserveSessionDao;

	/**
	 * {@inheritDoc}
	 */
	public boolean insert(final List<ReserveSession> reserveSessionList) {
		boolean resultFlag = false;
		if (null != reserveSessionList && reserveSessionList.size() > 0) {
			for (ReserveSession reserveSession : reserveSessionList) {
				resultFlag = reserveSessionDao.insert(reserveSession);
				if (!resultFlag) {
					throw new RuntimeException("批量新增表信息异常");
				}
			}
		}

		return resultFlag;
	}

	/**
	 * {@inheritDoc}
	 */
	public boolean insert(ReserveSession reserveSession) {
		return reserveSessionDao.insert(reserveSession);
	}

	/**
	 * {@inheritDoc}
	 */
	public boolean update(final ReserveSession reserveSession) {
		return reserveSessionDao.update(reserveSession);
	}

	/**
	 * {@inheritDoc}
	 */
	public List<ReserveSession> queryReserveSessionList(ReserveSessionQuery queryBean) {
		return reserveSessionDao.queryReserveSessionList(queryBean);
	}

	/**
	 * {@inheritDoc}
	 */
	public List<ReserveSession> queryReserveSessionListWithPage(ReserveSessionQuery queryBean, PageUtil pageUtil) {
		if (null == queryBean) {
			queryBean = new ReserveSessionQuery();
		}

		// 查询总数
		int totalItem = queryReserveSessionCount(queryBean);

		if (pageUtil == null) {
			pageUtil = new PageUtil();
		}
		pageUtil.setTotalRow(totalItem);
		pageUtil.init();

		if (totalItem > 0) {
			queryBean.setPageIndex(pageUtil.getCurPage());
			queryBean.setPageSize(pageUtil.getPageSize());
			// 调用Dao翻页方法
			return reserveSessionDao.queryReserveSessionListWithPage(queryBean);
		}
		return null;
	}

	/**
	 * {@inheritDoc}
	 */
	public int queryReserveSessionCount(ReserveSessionQuery queryBean) {
		return reserveSessionDao.queryReserveSessionCount(queryBean);
	}

	/**
	 * {@inheritDoc}
	 */
	public boolean delete(ReserveSession reserveSession) {
		return reserveSessionDao.delete(reserveSession);
	}

	/**
	 * {@inheritDoc}
	 */
	public ReserveSession getReserveSessionById(Long id) {
		return reserveSessionDao.getReserveSessionById(id);
	}

	/**
	 * {@inheritDoc}
	 */
	public boolean delete(final ReserveSession[] reserveSessions) {
		boolean resultFlag = false;
		if (null != reserveSessions && reserveSessions.length > 0) {
			for (int i = 0; i < reserveSessions.length; i++) {
				resultFlag = delete(reserveSessions[i]);
				if (!resultFlag) {
					throw new RuntimeException("批量删除表信息异常!");
				}
			}
		}

		return resultFlag;
	}

	/**
	 * {@inheritDoc}
	 */
	public boolean exist(ReserveSession reserveSession) {
		return reserveSessionDao.exist(reserveSession);
	}
}
